﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web
{
	public partial class login : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
            if (null != Session["username"]) 
            {
                Response.Redirect("usermain.aspx");
            }
		}

        protected void Search_Click(object sender, EventArgs e)
        {
            string userKey = TextBox_Search.Text;
            string url = "SearchResult.aspx?key=" + TextBox_Search.Text;
            Response.Redirect(url);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (TextBox3.Text == Session["gif"].ToString())
            {
                BLL.UserBLL userBll = (BLL.UserBLL)BLLFAC.DataAccess.CreateUser();
                //DAL.UserLoginDAL userLogin = (DAL.UserLoginDAL)DALFAC.DataAccess.CreateUserLogin();
                if (null != userBll)
                {
                    if (0 == userBll.Login(TextBox1.Text, TextBox2.Text))
                    {
                        Session["username"] = TextBox1.Text;
                        Response.Redirect("usermain.aspx");

                    }
                }
                else
                {
                    Session.Clear();
                    Response.Redirect("Error.aspx");
                }
            }
            else
            {
                Response.Redirect("login.aspx");
            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Session.Clear();
            Response.Redirect("register.aspx");
        }
	}
}